﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using WMS.FC.Domain.PersistenceObject.Business;
using WMS.FC.Infrastructure.Common;

namespace WMS.FC.Infrastructure.POConfig.Business
{
    public class CellConfig : POBaseConfig<CellPO>
    {
        public override void InitializeData(EntityTypeBuilder<CellPO> builder)
        {
        }

        public override void MapColumn(EntityTypeBuilder<CellPO> builder, ref int index)
        {
            builder.HasComment("电池表");
            builder.Property(entity => entity.Barcode).ConfigColumn("BARCODE", "电池条码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.MaterialCode).ConfigColumn("MATERIAL_CODE", "物料编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TechnologyRouteCode).ConfigColumn("TECHNOLOGY_ROUTE_CODE", "工艺路径编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.TechnologyProcessCode).ConfigColumn("TECHNOLOGY_PROCESS_CODE", "工艺工序编码", 50, true).HasColumnOrder(index++);
            builder.Property(entity => entity.OriginalNgCode).ConfigColumn("ORIGINAL_NG_CODE", "原始NG编码", 2000).HasColumnOrder(index++);
            builder.Property(entity => entity.NgCode).ConfigColumn("NG_CODE", "NG编码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.IsRework).ConfigColumn("IS_REWORK", "是否返修").HasColumnOrder(index++);
            builder.Property(entity => entity.ReworkCount).ConfigColumn("REWORK_COUNT", "返修次数").HasColumnOrder(index++);
            builder.Property(entity => entity.RankValue).ConfigColumn("RANK_VALUE", "分选等级", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.TrayBarcode).ConfigColumn("TRAY_BARCODE", "托盘条码", 50).HasColumnOrder(index++);
            builder.Property(entity => entity.CellPosition).ConfigColumn("CELL_POSITION", "电池位置").HasColumnOrder(index++);
            builder.Property(entity => entity.Status).ConfigColumn("STATUS", "电池状态", 2000).HasColumnOrder(index++);
            builder.Property(entity => entity.WarehouseCode).ConfigColumn("WAREHOUSE_CODE", "仓库编码", 50, true).HasColumnOrder(index++);
        }

        public override void MapIndex(EntityTypeBuilder<CellPO> builder)
        {
            builder.HasIndex(entity => new { entity.Barcode, entity.WarehouseCode }).HasDatabaseName($"UN_{TableName}_1").IsUnique();
        }
    }
}
